# conding = utf-8
from selenium.webdriver import ActionChains, Keys

from pages.page import Page
from pages.lyz.pycache.client import left_menu_sys, left_menu, btn_unfold, member, member_options, find_btn, detail, name_send, \
    id_send, detail_btn, historical_id, historical_fend, historical_options, historical_state, state_options, \
    information, \
    information_options, detail_tow, cancel_one, cancel_tow, cancel_three, find_expected, historical_btn, select_btn, \
    reset, finance


class ClientPages(Page):

    def open_sales_order(self):
        '''
        打开管理员UI，如果已经打开则不会执行单击动作
        :return:
        '''
        if self.display(left_menu) is False:  # 如果是隐藏状态则单击
            self.click(left_menu_sys)
        self.click(left_menu)

    def btn_unfold(self):
        self.click(btn_unfold)

    def member(self):
        self.click(member)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def find_btn(self):
        self.click(find_btn)

    def detail(self):
        self.click(detail)

    def name_send(self, value):
        self.send_keys(name_send, value)

    def id_send(self, value):
        self.send_keys(id_send, value)

    def detail_btn(self):
        self.click(detail_btn)

    def historical_btn(self):
        self.click(historical_btn)

    def historical_id(self, value):
        self.send_keys(historical_id, value)

    def historical_fend(self):
        self.click(historical_fend)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.UP)
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def historical_state(self):
        self.click(historical_state)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.UP)
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def finance(self):
        self.click(finance)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def information(self):
        self.click(information)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def select_btn(self):
        self.click(select_btn)

    def detail_tow(self):
        self.click(detail_tow)

    def reset(self):
        self.click(reset)

    def cancel_one(self):
        self.click(cancel_one)

    def cancel_tow(self):
        self.click(cancel_tow)

    def cancel_three(self):
        self.click(cancel_three)

    def search_result_text(self, value):
        '''
        单击查找完成后，获取查找结果
        :return:
        '''
        if value == 'SK00000000708':
            return self.text(find_expected)
